Skip to content

We introduce a cache to avoid computing find_necessary_steps during each inference call#10

Merged
huyng merged 2 commits intomasterfrom
multithreading_fix
Feb 22, 2018
Merged

We introduce a cache to avoid computing find_necessary_steps during each inference call#10
huyng merged 2 commits intomasterfrom
multithreading_fix

Conversation

@huyng
Copy link
Copy Markdown
Contributor

@huyng huyng commented Feb 22, 2018

@tobibaum

I've introduced a cache to avoid computing find_necessary_steps multiple times during each inference call. This has 2 benefits: 1) it reduces computation time of the compute call 2) it avoids a subtle multi-threading bug in networkx when accessing the graph from a high number of threads.

The following test should fail without these changes:

https://github.com/yahoo/graphkit/compare/multithreading_fix?expand=1#diff-eb68f4dabe94fb4dfdc148f0ef8961f8R283

Thanks for reviewing!

Copy link
Copy Markdown

@tobibaum tobibaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! just the little typo in the test.

inputs_keys = tuple(sorted(inputs.keys()))
cache_key = (inputs_keys, outputs)
if cache_key in self._necessary_steps_cache:
return self._necessary_steps_cache[cache_key]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had no idea you could have a tuple of tuples as a key. seems to work though.

pipeline = compose(name="pipeline", merge=True)(
operation(name="op_a", needs=['a', 'b'], provides='c')(op_a),
operation(name="op_b", needs=['c', 'b'], provides='d')(op_b),
operation(name="op_c", needs=['a', 'b'], provides='e')(op_b),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(...)(op_c)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks, good catch

@codecov-io
Copy link
Copy Markdown

codecov-io commented Feb 22, 2018

Codecov Report

Merging #10 into master will increase coverage by 0.59%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #10      +/-   ##
=========================================
+ Coverage   77.21%   77.8%   +0.59%     
=========================================
  Files           5       5              
  Lines         338     347       +9     
=========================================
+ Hits          261     270       +9     
  Misses         77      77
Impacted Files Coverage Δ
graphkit/network.py 70.2% <100%> (+1.41%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d3f8a8a...429c3d1. Read the comment docs.

@huyng
Copy link
Copy Markdown
Contributor Author

huyng commented Feb 22, 2018

Okay updated the test and verified that no errors occur

@tobibaum
Copy link
Copy Markdown

👍

@huyng huyng merged commit af0f7b2 into master Feb 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants